package com.example.demo.web;

import com.example.demo.dao.BookMonthMapper;
import com.example.demo.dao.BookUserMapper;
import com.example.demo.entity.BookMonth;
import com.example.demo.entity.BookUser;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("user")
@Controller
public class BookControl {
//bookUser表链接到前端
    @Autowired
    BookUserMapper bookUserMapper;
    @Autowired
    BookMonthMapper bookMonthMapper;
    @PostMapping("charts")
    @ResponseBody
    public Map charts(){
        Map map=new HashMap();
        List<BookUser> list=bookUserMapper.list1();
        String[] num=new String[list.size()];
        String[] name=new String[list.size()];
        for (int i=0;i<list.size();i++) {
            num[i]=list.get(i).getNub();
            name[i]=list.get(i).getName();
        }
        map.put("xx",num);
        map.put("nn",name);
        List<BookMonth> list1=bookMonthMapper.list2();
        String[] month=new String[list1.size()];
        String[] nub=new String[list1.size()];
        for (int j=0;j<list1.size();j++){
            month[j]=list1.get(j).getMonth();
            nub[j]=list1.get(j).getNub();
        }
        map.put("mm",month);
        map.put("nub",nub);
        return map;
    }


//    @PostMapping("charts")
//    @ResponseBody
//    public Map month(){
//        Map map=new HashMap();
//        List<BookMonth> list=bookMonthMapper.list2();
//        String[] month=new String[list.size()];
//        String[] nub=new String[list.size()];
//        for (int j=0;j<list.size();j++){
//            month[j]=list.get(j).getMonth();
//            nub[j]=list.get(j).getNub();
//        }
//        map.put("mm",month);
//        map.put("nub",nub);
//        return map;
//    }
}
